<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 没有 async await 情况
      // function async1() {
      //   console.log(1)
      //   async2()
      //   console.log(2)
      // }

      // function async2() {
      //   console.log(3)
      // }

      // console.log(4)
      // setTimeout(() => {
      //   console.log(5)
      // }, 0)

      // async1()

      // // Promise.resolve()和new Promise(() => xxx)
      // new Promise((resolve) => {
      //   console.log(6)
      //   resolve()
      // }).then(() => {
      //   console.log(7)
      // })

      // console.log(8)
      // 4 1 3 2 6 8 7 5

      // 有 async await 的情况
      async function async1() {
        console.log(1)
        await async2()
        console.log(2)
      }

      async function async2() {
        console.log(3)
      }

      console.log(4)
      setTimeout(() => {
        console.log(5)
      }, 0)

      async1()

      // Promise.resolve()和new Promise(() => xxx)
      new Promise((resolve) => {
        console.log(6)
        resolve()
      }).then(() => {
        console.log(7)
      })

      console.log(8)
      // 4 1 3 6 8 2 7 5
    </script>
  </body>
</html>
